package com.wootion.cims.module.systemsetting.polt.controller;

import com.wootion.cims.module.systemsetting.dictionary.model.LogAnotion;
import com.wootion.cims.module.systemsetting.polt.dto.SysPlotDto;
import com.wootion.cims.module.systemsetting.polt.service.SysPlotService;
import com.wootion.cims.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: LanQiang
 * @Date: 2022/11/21/11:23
 * @Description: 作用xxx
 */
@Slf4j
@RequestMapping(value = {"/plot"})
@RestController
@Api(value = "小区管理")
@RequiresAuthentication
public class SysPlotController {
    @Resource
    private SysPlotService sysPlotService;

    /**
     * 查询所有小区信息/或按照条件查询,并分页返回
     * @param condition
     * @param limit
     * @param page
     * @return
     */
    @PostMapping(path = {"/list"})
    @ApiOperation(value = "小区管理-小区列表查询", httpMethod = "POST",notes = "如果需要按照条件查询就传入condition小区名称关键字,condition是字符串类型,不是jso格式,而是K-V结构,例如：condition:金色家园小区 page:2 limit:20")
    public ResponseResult list(@RequestParam(required = false) String condition,
                               @RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "18") Integer limit){
        return sysPlotService.list(condition,page,limit);
    }

    /**
     * 添加/修改时，查询小区所属的社区分组
     * @param 
     * @return
     */
    @GetMapping(path = {"/group"})
    @ApiOperation(value = "小区管理-社区分组", httpMethod = "GET",notes = "")
    public ResponseResult group(){
        return sysPlotService.groupPlot();
    }

    /**
     * 添加小区
     * @param sysPlotDto
     * @return
     */
    @LogAnotion(type = "新增",value = "0",incident = "小区信息",prefixContent = "小区名称")
    @PostMapping(path = {"/save"},consumes = {MediaType.APPLICATION_JSON_VALUE})
    @ApiOperation(value = "小区管理-添加小区", httpMethod = "POST", consumes = MediaType.APPLICATION_JSON_VALUE,notes = "{\"name\":\"汤臣一品小区\",\"area\":\"80\",\"address\":\"星光大道6号路\",\"sysCommunity\":{\"name\":\"桃园社区02\"}}")
    public ResponseResult save(@RequestBody @Validated SysPlotDto sysPlotDto){
        return sysPlotService.save(sysPlotDto);
    }

    /**
     * 修改小区
     * @param sysPlotDto
     * @return
     */
    @PostMapping(path = {"/update"},consumes = {MediaType.APPLICATION_JSON_VALUE})
    @ApiOperation(value = "小区管理-修改小区", httpMethod = "POST", consumes = MediaType.APPLICATION_JSON_VALUE,notes = "{\"name\":\"汤臣一品小区\",\"area\":\"80\",\"address\":\"星光大道6号路\",\"sysCommunity\":{\"name\":\"桃园社区02\"}}")
    public ResponseResult update(@RequestBody @Validated SysPlotDto sysPlotDto, HttpServletRequest request){
        return sysPlotService.update(sysPlotDto,request);
    }

    /**
     * 删除小区
     * @param sysPlotDto
     * @return
     */
    @LogAnotion(type = "删除",value = "0",incident = "小区信息",prefixContent = "小区名称")
    @PostMapping(path = {"/delete"},consumes = {MediaType.APPLICATION_JSON_VALUE})
    @ApiOperation(value = "小区管理-删除小区", httpMethod = "POST", consumes = MediaType.APPLICATION_JSON_VALUE,notes = "{\"id\":\"1\"}")
    public ResponseResult delete(@RequestBody SysPlotDto sysPlotDto){
        return sysPlotService.deletePlot(sysPlotDto);
    }
}
